package com.framework.modules.dataview.controller;

import java.util.Arrays;
import java.util.Map;

import com.framework.common.validator.ValidatorUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.framework.modules.dataview.entity.ViewUserFullInfoEntity;
import com.framework.modules.dataview.service.ViewUserFullInfoService;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;


/**
 * VIEW
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-11-05 09:51:47
 */
@RestController
@RequestMapping("dataview/viewuserfullinfo")
@Api(tags = "ViewUserFullInfoController")
public class ViewUserFullInfoController {
    @Autowired
    private ViewUserFullInfoService viewUserFullInfoService;

    /**
     * 用户列表
     */
    @RequestMapping("/list")
        @RequiresPermissions("dataview:viewuserfullinfo:list")
        @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params){
        String nickname=(String)params.get("nickname");
        String user_id=(String)params.get("user_id");
        String is_verify_idcard=(String)params.get("is_verify_idcard");
        if(StringUtils.isBlank(user_id)){
            params.remove("user_id");
        }
        if(StringUtils.isBlank(is_verify_idcard)){
            params.remove("is_verify_idcard");
        }
        if(StringUtils.isBlank(nickname)){
            params.remove("nickname");
        }
        PageUtils page = viewUserFullInfoService.queryPage(params);
        return R.ok().put("page",page);
    }

    /**
     * 主播列表
     */
    @RequestMapping("/getLiverInfolist")
    @RequiresPermissions("dataview:viewuserfullinfo:list")
    @ApiOperation("getLiverInfolist")
    public R getLiverInfolist(@RequestParam Map<String, Object> params){
        params.put("is_live_streamer",1);
        String nickname=(String)params.get("nickname");
        String user_id=(String)params.get("user_id");
        String guild_id=(String)params.get("guild_id");
        String is_verify_idcard=(String)params.get("is_verify_idcard");
        if(StringUtils.isBlank(user_id)){
            params.remove("user_id");
        }
        if(StringUtils.isBlank(guild_id)){
            params.remove("guild_id");
        }
        if(StringUtils.isBlank(is_verify_idcard)){
            params.remove("is_verify_idcard");
        }
        if(StringUtils.isBlank(nickname)){
            params.remove("nickname");
        }
        PageUtils page = viewUserFullInfoService.queryPage(params);
        return R.ok().put("page",page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
        @RequiresPermissions("dataview:viewuserfullinfo:info")
        @ApiOperation("info")
    public R info(@PathVariable("userId") Long userId){
        ViewUserFullInfoEntity viewUserFullInfo = viewUserFullInfoService.selectById(userId);

        return R.ok().put("data", viewUserFullInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        @RequiresPermissions("dataview:viewuserfullinfo:save")
        @ApiOperation("save")
    public R save(@RequestBody ViewUserFullInfoEntity viewUserFullInfo){
        viewUserFullInfoService.insert(viewUserFullInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        @RequiresPermissions("dataview:viewuserfullinfo:update")
        @ApiOperation("update")
    public R update(@RequestBody ViewUserFullInfoEntity viewUserFullInfo){
        ValidatorUtils.validateEntity(viewUserFullInfo);
        viewUserFullInfoService.updateAllColumnById(viewUserFullInfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        @RequiresPermissions("dataview:viewuserfullinfo:delete")
        @ApiOperation("delete")
    public R delete(@RequestBody Long[] userIds){
        viewUserFullInfoService.deleteBatchIds(Arrays.asList(userIds));

        return R.ok();
    }

}
